var api = new require("./index").WechatPayAPI({
		appid:"XXXXXXXXXXXXXXXX",
		mch_id:"XXXXXXXXXXX",
		partner_key:"XXXXXXXXXXXXXXXX",
		cert:"certs/apiclient_cert.pem",
		cert_key:"certs/apiclient_key.pem"
	});
//var item = {batch:"v0101",name:"tedi3231",age:2030};
//var str = api._generate_string_form_obj(item);
//console.log(str);
function test_unifiedorder(){
	var order_item = {
		notify_url:"http://wedo.avosapps.com/order/aa.php",
		openid:"opmukt4SZzas_TinMqpT5JkC3z6Q",
		out_trade_no:Number.parseInt(Math.random()*1000000),
		spbill_create_ip:"14.23.150.211",
		total_fee:1,
		trade_type:"NATIVE",
		body:"aavv"
	};
	api.unifiedorder(order_item).then(function(data){
		console.log(data);
	}).fail(function(err){
		console.log(err);
	});
}
test_unifiedorder();
api.orderquery("1005450053201511261776573190","").then(function(data){
	console.log(data);
}).fail(function(err){
	console.log(err);
});
/*
api.closeorder("35370664").then(function(data){
	console.log(data);
}).fail(function(err){
	console.log(err);
});
*/
/*
api.orderquery("1005450053201511261776573190","").then(function(data){
	console.log("data is ",data);
});
*/
/*
var api = new require("./wxapi")("wxbd626ed750b05e5f","ca545a10101efc536107e8cf9eda83f7");
api.get_token().then(function(access_token){
	console.log("access_token 1 is ",access_token);
});

setTimeout(function(){
	api.get_token().then(function(access_token){
		console.log("access_token 2 is ",access_token);
	});
},10000);

api.get_ticket().then(function(access_token){
	console.log("ticket 1 ",access_token);
});

setTimeout(function(){
	api.get_ticket().then(function(access_token){
		console.log("ticket 2 " ,access_token);
	});
},10000);
setTimeout(function(){
	api.get_sns_token("001d2b3c211a0b1858ee558bc9210388").then(function(res){
		console.log("ticket 1 ",res);
	});
},10000);
*/
/*
var https = require("https");
function test_https(){
	var options = {
	  hostname: 'mail.qq.com',
	  port: 443,
	  path: '/',
	  method: 'GET',
	}; 
	var req = https.request(options,function(res){
		console.log("Jejjjj");
		console.log(res);
	});
	req.end();
}
*/
/*
https.get('https://mail.qq.com/', function(res) {
  	console.log("statusCode: ", res.statusCode);
	console.log("headers: ", res.headers);
	res.on('data', function(d) {
			process.stdout.write(d);
	});
	}).on('error', function(e) {
		console.error(e);
  	});
*/
//test_https();

/*
var q = require("q");
function test_promise(){
	function one(){
		var deferred  = q.defer();
		deferred.resolve(500);
		return deferred.promise;
	}
	one().then(function(data){ console.log(data);});
}
test_promise();
*/

//测试退款功能
function test_refund(){
	var params = {
		device_info:"WEB",
		transaction_id:"1005270053201511261778229445",
		out_refund_no:"REFUND0001",
		total_fee:1,
		refund_fee:1,
		refund_fee_type:"CNY",
		op_user_id:"1289247501"
	};	
	api.refund(params).then(function(data){
		console.log("refund data is ", data);
	}).fail(function(err){
		console.log("refund erro is",err);
	});
}

function test_refundquery(){
	var params = {
		device_info:"WEB",
		transaction_id:"1005270053201511261778229445",
		out_refund_no:"REFUND0001",
	};	
	api.refund(params).then(function(data){
		console.log("refundquery data is ", data);
	}).fail(function(err){
		console.log("refundquery erro is",err);
	});
}
//test_refund();

function test_generate_barcode_url(){
	var url = api.generate_barcode_url(Number.parseInt(Math.random()*100000000));
	console.log("barcode url is ",url);
}
test_generate_barcode_url();

